package UML_ER.diagram.part;


import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.StringReader;
import java.lang.reflect.InvocationTargetException;
import java.net.URI;
import java.sql.Date;

import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.window.Window;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.layout.RowData;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.dialogs.WizardNewFileCreationPage;
import org.eclipse.ui.ide.undo.CreateFileOperation;
import org.eclipse.ui.ide.undo.WorkspaceUndoUtil;
import org.eclipse.ui.internal.ide.IDEWorkbenchMessages;
import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
import org.eclipse.wb.swt.layout.grouplayout.GroupLayout;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;

/**
 * @generated
 */
public class UML_ERCreationQuestionaireWizardPage extends WizardPage {

	
	private final String fileExtension;
	
	// cache of newly-created file
	private IFile newFile;

	
	private Button male;
	private Button female;
	private Text lastNameText;
	private Text nameText;
	private Text modellingCoursesText;

	private String lastName;
	private String name;
	private String gender;
	private String experiment = "OntologyDriven Business Modelling experiment - Valencia";
	private String tool = "REAtool";
	private Date date;
	private String numberOfModellingCourses;
	private String program;

	
	

	
	public UML_ERCreationQuestionaireWizardPage(String pageName, String fileExtension) {
		super("Create Questionnaire");
		this.fileExtension = fileExtension;
	}

	/**
	 * Override to create files with this extension.
	 * 
	 * @generated
	 */
	protected String getExtension() {
		return fileExtension;
	}

	
	
	@SuppressWarnings("restriction")
	protected IFile createFileHandle(IPath filePath) {
		return IDEWorkbenchPlugin.getPluginWorkspace().getRoot().getFile(
				filePath);
	}
	
	protected InputStream getInitialContents() {
		String contents;
		contents = "1" + ";" + lastName + "\n";
		contents += "2" + ";" + name + "\n";
		if(male.getSelection())
			contents += "3" + ";" + "male" +"\n";
		else
			contents += "3" + ";" + "female" +"\n";
		return  new java.io.StringBufferInputStream(contents);
		
	}
	
	
	public IFile createNewFile(IProgressMonitor monitor) {
		if (newFile != null) {
			return newFile;
		}

		// create the new file and cache it if successful
		
		lastName = lastNameText.getText();
		name = nameText.getText();
		IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject("Test-ER");
		final IFile newFileHandle = project.getFile(lastName + name +  "." + getExtension());
		final InputStream initialContents = getInitialContents();
		
		try {
			newFileHandle.create(initialContents, false, monitor);
		} catch (CoreException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		newFile = newFileHandle;

		return newFile;
	}



	/**
	 * 
	 */
	public void createControl(Composite parent) {
		
		/*Composite composite = new Composite(parent, SWT.NONE);
	    composite.setLayout(new GridLayout(2, true));
	    
	    new Label(composite, SWT.LEFT).setText("Last Name:");
	    lastNameText = new Text(composite, SWT.LEFT);
	    lastNameText.setTextLimit(40);
	    
	    new Label(composite, SWT.LEFT).setText("Name:");
	    nameText = new Text(composite, SWT.LEFT);

	    new Label(composite, SWT.LEFT).setText("Gender:");
	    Composite yesNo = new Composite(composite, SWT.NONE);
	    yesNo.setLayout(new FillLayout(SWT.VERTICAL));

	    male = new Button(yesNo, SWT.RADIO);
	    male.setText("male");

	    female = new Button(yesNo, SWT.RADIO);
	    female.setText("female");
	    
	    new Label(composite, SWT.LEFT).setText("Number of previous modelling courses:");
	    modellingCoursesText = new Text(composite, SWT.LEFT);*/
	    
	    Composite perceptionQuestions = new Composite(parent, SWT.NONE);
	   
	    
	    
	    setControl(perceptionQuestions);
	    perceptionQuestions.setLayout(new GridLayout(6, false));
	    
	    Label lblQuestion = new Label(perceptionQuestions, SWT.NONE);
	    lblQuestion.setText("question");
	    
	    Label lblStronglyDisagree = new Label(perceptionQuestions, SWT.NONE);
	    lblStronglyDisagree.setAlignment(SWT.CENTER);
	    lblStronglyDisagree.setText("strongly disagree");
	    
	    Label lblDisagree = new Label(perceptionQuestions, SWT.NONE);
	    lblDisagree.setText("disagree");
	    
	    Label lblNeutral = new Label(perceptionQuestions, SWT.NONE);
	    lblNeutral.setText("neutral");
	    
	    Label lblAgree = new Label(perceptionQuestions, SWT.NONE);
	    lblAgree.setText("agree");
	    
	    Label lblStronglyAgree = new Label(perceptionQuestions, SWT.NONE);
	    lblStronglyAgree.setText("strongly agree");
	    
	    Label lblNewLabel = new Label(perceptionQuestions, SWT.NONE);
	    lblNewLabel.setText("New Label");
	    
	    Button btnRadioButton_2 = new Button(perceptionQuestions, SWT.RADIO);
	    btnRadioButton_2.addMouseListener(new MouseAdapter() {
	    	@Override
	    	public void mouseDown(MouseEvent e) {
	    	}
	    });
	    btnRadioButton_2.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1));
	    btnRadioButton_2.setAlignment(SWT.CENTER);
	    btnRadioButton_2.addSelectionListener(new SelectionAdapter() {
	    	@Override
	    	public void widgetSelected(SelectionEvent e) {
	    	}
	    });
	    
	    Button button = new Button(perceptionQuestions, SWT.RADIO);
	    button.addMouseListener(new MouseAdapter() {
	    	@Override
	    	public void mouseDown(MouseEvent e) {
	    	}
	    });
	    button.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1));
	    
	    Button button_1 = new Button(perceptionQuestions, SWT.RADIO);
	    button_1.addMouseListener(new MouseAdapter() {
	    	@Override
	    	public void mouseDown(MouseEvent e) {
	    	}
	    });
	    button_1.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1));
	    
	    Button button_2 = new Button(perceptionQuestions, SWT.RADIO);
	    button_2.addMouseListener(new MouseAdapter() {
	    	@Override
	    	public void mouseDown(MouseEvent e) {
	    	}
	    });
	    button_2.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1));
	    
	    Button button_3 = new Button(perceptionQuestions, SWT.RADIO);
	    button_3.addMouseListener(new MouseAdapter() {
	    	@Override
	    	public void mouseDown(MouseEvent e) {
	    	}
	    });
	    button_3.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1));
	   
	    
		setPageComplete(validatePage());
	}

	protected boolean validatePage() {
		return true;
	}
}
